package com.dly.blog.config;

import com.dly.blog.plugin.UploadFilePlugin;
import com.dly.blog.properties.UploadProperties;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.plugin.core.config.EnablePluginRegistries;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/12 22:30
 */
@Data
@Configuration
//开启插件配置
@EnablePluginRegistries(UploadFilePlugin.class)
@EnableConfigurationProperties(UploadProperties.class)
public class OssConfig {

    private final UploadProperties uploadProperties;

    @Bean
    @ConditionalOnProperty(name = "blog.upload.minio.enable", havingValue = "true")
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(uploadProperties.getMinio().getEndpoint())
                .credentials(uploadProperties.getMinio().getAccessKey(), uploadProperties.getMinio().getSecretKey())
                .build();
    }
}
